  /******************************************************************************
  * @file    PT32X005_tim.h
  * @author  应用开发团队
  * @version V1.1.0
  * @date    2020/1/27
  * @brief    This file contains all the functions prototypes for the TIM firmware library.
  *
  ******************************************************************************
  * @attention
  *
  *
  *****************************************************************************/

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef PT32X005_TIM_H
#define PT32X005_TIM_H

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "PT32X005.h"


/** @addtogroup PWM **/

/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
#define TIM_CNT_MODE_UP                ((u32)0x00000000)
#define TIM_CNT_MODE_DOWN              ((u32)0x00000008)

#define IS_TIM_ALL_PERIPH(PERIPH)            (((PERIPH) == TIM2) ||((PERIPH) == TIM3) || ((PERIPH) == TIM4))

#define IS_TIM_COUNTER_MATCH(VALUE)          ((VALUE) <= 0xFFFF)

#define IS_TIM_COUNTER_VALUE(COUNTERVALUE)   ((COUNTERVALUE) <= 0xFFFF)

#define IS_TIM_PRESCALER(PRESCALER)	((PRESCALER) <= 0xFFFF)

#define IS_TIM_COUNTERMODE(COUNTERMODE)      (((COUNTERMODE) == TIM_CNT_MODE_UP) || \
        ((COUNTERMODE) == TIM_CNT_MODE_DOWN))

#define IS_TIM_INT(TIM_INT)	((TIM_INT)  == TIMx_CR2_ARI)

#define IS_TIM_FLAG(TIM_FLAG)	((TIM_FLAG) == TIMx_SR_ARF)

/** @brief Definition of PWM timebase init structure. **/
typedef struct
{
	u16	MatchValue;            /*!< Period (Value for MR0 register)             */
	u8	Prescaler;             /*!< Prescaler (Value for PR register)           */
	u8	CounterMode;           /*!< Counter mode up-counting or down-counting   */
	FunctionalState    OVRSTEN;
} TIM_TimeBaseInitTypeDef;

/* Exported macro ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------------------------------------*/
void TIM_TimeBaseInit(TIMx_TypeDef* TIMx, TIM_TimeBaseInitTypeDef* TimeBaseInit);
void TIM_TimeBaseStructInit(TIM_TimeBaseInitTypeDef* TimeBaseInit);
void TIM_SetPrescaler(TIMx_TypeDef* TIMx, u8 Prescaler);
void TIM_SetAutoreload(TIMx_TypeDef* TIMx, u16 Reload);
void TIM_SetCounter(TIMx_TypeDef* TIMx, u16 Counter);
u16 TIM_GetCounter(TIMx_TypeDef* TIMx);
u16 TIM_GetPrescaler(TIMx_TypeDef* TIMx);
void TIM_UpdateCmd(TIMx_TypeDef* TIMx);
void TIM_Cmd(TIMx_TypeDef* TIMx, FunctionalState NewState);
void TIM_ITConfig(TIMx_TypeDef* TIMx, u32 TIM_IT, FunctionalState NewState);
FlagStatus TIM_GetFlagStatus(TIMx_TypeDef* TIMx, u32 TIM_FLAG);
void TIM_ClearFlag(TIMx_TypeDef* TIMx, u32 TIM_FLAG);

/**
  * @}
  */


#ifdef __cplusplus
}
#endif

#endif


